package com.ruoyi.ihome.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ihome.domain.IhTopicComment;
import com.ruoyi.ihome.service.IIhTopicCommentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 帖子评论管理Controller
 * 
 * @author mirage
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/ihome/topicComment")
public class IhTopicCommentController extends BaseController
{
    @Autowired
    private IIhTopicCommentService ihTopicCommentService;

    /**
     * 查询帖子评论管理列表
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicComment:list')")
    @GetMapping("/list")
    public TableDataInfo list(IhTopicComment ihTopicComment)
    {
        startPage();
        List<IhTopicComment> list = ihTopicCommentService.selectIhTopicCommentList(ihTopicComment);
        return getDataTable(list);
    }

    /**
     * 导出帖子评论管理列表
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicComment:export')")
    @Log(title = "帖子评论管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IhTopicComment ihTopicComment)
    {
        List<IhTopicComment> list = ihTopicCommentService.selectIhTopicCommentList(ihTopicComment);
        ExcelUtil<IhTopicComment> util = new ExcelUtil<IhTopicComment>(IhTopicComment.class);
        util.exportExcel(response, list, "帖子评论管理数据");
    }

    /**
     * 获取帖子评论管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicComment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ihTopicCommentService.selectIhTopicCommentById(id));
    }

    /**
     * 新增帖子评论管理
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicComment:add')")
    @Log(title = "帖子评论管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IhTopicComment ihTopicComment)
    {
        System.out.println(ihTopicComment);
        return toAjax(ihTopicCommentService.insertIhTopicComment(ihTopicComment));
    }

    @PostMapping("/insertihtopiccomment")
    public AjaxResult insertIhTopicComment(@RequestBody IhTopicComment ihTopicComment) {
        System.out.println(ihTopicComment);
        return toAjax(ihTopicCommentService.insertIhTopicComment(ihTopicComment));
    }
    /**
     * 修改帖子评论管理
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicComment:edit')")
    @Log(title = "帖子评论管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IhTopicComment ihTopicComment)
    {
        return toAjax(ihTopicCommentService.updateIhTopicComment(ihTopicComment));
    }

    /**
     * 删除帖子评论管理
     */
    @PreAuthorize("@ss.hasPermi('ihome:topicComment:remove')")
    @Log(title = "帖子评论管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ihTopicCommentService.deleteIhTopicCommentByIds(ids));
    }
}
